package com.duobaoyu.dby.supply.biz.client.boundary.channel;

import com.duobaoyu.dby.channel.adapter.service.AbstractSupplyOrderService;
import com.duobaoyu.dby.supply.biz.client.resource.ResourceApiClient;
import com.duobaoyu.dby.supply.biz.client.resource.bean.bo.OrderRuleConfigBO;
import com.duobaoyu.dby.supply.biz.util.IdGeneratorUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName SupplyChainOrderConfigService
 * @Description 渠道订单配置
 * @createTime 13:24:00 2023/10/11
 */
@Component
@RequiredArgsConstructor
public class SupplyChainOrderConfigService extends AbstractSupplyOrderService {

    private final ResourceApiClient resourceApiClient;

    @Override
    public Integer getOrderConfig(String channelCode) {
        OrderRuleConfigBO orderRuleConfig = resourceApiClient.queryOrderRuleConfig(channelCode);
        return Optional.ofNullable(orderRuleConfig).map(OrderRuleConfigBO::getOrderRule).map(OrderRuleConfigBO.OrderRule::getSkuSplitVarietyCount).orElse(999);
    }

    @Override
    public String orderSnGenerator(String channelCode, String bizCode) {
    	return IdGeneratorUtil.getOrderSn(channelCode,bizCode);
    }
}
